OpenBuildings GenerativeComponents Help

The DataRow Class

This class represents one row of data in a DataTable. Every row in a DataTable has the same structure (which corresponds to the column structure of the overall table).

This class has no constructors; you can't simply create a data row "out of nowhere." To create a new data row on an existing table, you call the table's NewRow method.

An interesting aspect of a DataRow is that each of its column values is exposed as a read/write property. For example, if the table's column structure includes columns named 'NodeName', 'X', and 'Y', you could do this:
DataRow row = tbl.NewRow();
row.NodeName = 'MyPoint';
row.X = 2;
row.Y = -1.5; 

Since a DataRow object represents an actual row in the table, any changes you make to a data row's column values (such as the property assignments shown above) are automatically stored in the table.

Here are the properties and methods of the DataRow class:

void Clear()

This method clears all of the values in this data row (just as when it was first created).

void ClearColumn(columnIndicator)

This method clears the value in the specified column in this data row. Its argument is:

value columnIndicator
This identifies the specific column. It may be any one of the following:
  1. An integer, which specifies the column's position within the table's column structure. (The first column position is zero.)
  2. A string, which specifies the column's name.
  3. A DataColumn object.

void Delete()

This method deletes this row from the table.

value[] GetValues()

This method returns a list of all values in this data row, in column sequence.

value GetColumnValue(columnIndicator)

This method gets the value in the specified column in this data row.

This is not the usual way to get a value. The usual way is to read the property that corresponds to the column:
DataRow row = tbl[2];              // Obtain a data row somehow.
 
double angle;
 
angle = row.GetColumnValue('ArcAngle');  // This works, but…
 
angle = row.ArcAngle;                    // …this is the usual way
                                         // to do it.

This method's argument is:

value columnIndicator
This identifies the specific column. It may be any one of the following:
  1. An integer, which specifies the column's position within the table's column structure. (The first column position is zero.)
  2. A string, which specifies the column's name.
  3. A DataColumn object.

int RowIndex { get; }

This read-only property gives the index of this data row within its parent data table. The first row is at index zero.

void SetColumnValue(columnIndicator, data)

This method sets the value in the specified column in this data row.

This is not the usual way to set a value. The usual way is to assign to the property that corresponds to the column:
DataRow row = tbl[2];                // Obtain a data row somehow.
 
row.SetColumnValue('ArcAngle', 30);  // This works, but…
 
row.ArcAngle = 30;                   // …this is the usual way
                                     // to do it.
 

This method's arguments are:

value columnIndicator
This identifies the specific column. It may be any one of the following:
  1. An integer, which specifies the column's position within the table's column structure. (The first column position is zero.)
  2. A string, which specifies the column's name.
  3. A DataColumn object.

value data

The new value that is to be stored in the specified column of this row.

void SetValues(…)

This method sets all the values in this data row.

This method can take a single argument, which is a list of the values in column sequence:

Or, this method can take an arbitrary number of arguments, which are the values in column sequence.

void SetValuesFrom(DataRow source)

This method sets the values in this data row from the values in another data row.

The values are assigned by matching column names between the two data rows. The data rows can belong to different tables, and can have different column structures.

DataTable Table { get; }

This read-only property gives the data table to which this data row belongs.